Page({

  /**
   * 页面的初始数据
   */
  data: {
    activeIndex:0,
    listData:[
      {
        id:0,
        name:"家常菜",
        isActive:true
      },{
        id:1,
        name:"下饭菜",
        isActive:true
      },{
        id:2,
        name:"朋友聚餐",
        isActive:true
      },{
        id:3,
        name:"煮",
        isActive:true
      },{
        id:4,
        name:"汤类",
        isActive:true
      },{
        id:5,
        name:"西餐",
        isActive:true
      }
    ],
    inputValue:'', //输入框value值
    noData:false, //暂无数据
    carList:[],//搜索列表
    caidaninfo:[

    ],
    caidanxx:{
      pic:'',
      arrinfo:{}
    }

  },
  goToSearch:function(){
    wx.navigateTo({
      url: '../sousuo/sousuo',
    })
  },

  close: function () {
    var that = this
    that.setData({
      inputValue: '',
      carList:'',
      noData:false,
      closeImg: false,
      history:true
    })
  },
  onPageScroll:function(e){
    let me = this;
    //tab的吸顶效果
  console.log(e.scrollTop > me.data.tabTop)
    if(e.scrollTop>me.data.tabTop){
        if(me.data.tabFix){
            return
        }else{
            me.setData({
                tabFix:'Fixed'
            })
        }
    }else{
        me.setData({
            tabFix:''
        })
    }
},
/*   jump:function(){
    wx.pageScrollTo({
      duration: 300,
      scrollTop:topHight
    })
  }, */
/*   scrtop:function(e){
    let index = e.currentTarget.dataset.activeIndex;
    let that = this;
    this.scrtop(index);
  }, */
 // 点击左侧菜单项选择
 selectMenu: function(e) {
  /* this.jump */
   console.log(e);
  let index = e.currentTarget.dataset.index;
  let that = this
 /*  this.scrtop(activeIndex); */
  console.log(index)
  that.setData({
    activeIndex: index,
    toView: "a" + index,
  })
  if(index==0){
    wx.request({
      url: 'https://www.daizhongdai.xyz:3007/classify?zid=家常菜',
      success:res=>{
        console.log(res.data.data.data);
        this.setData({
          caidan:res.data.data.data,
        })
      }
    })
  }else if(index==1){
    wx.request({
      url: 'https://www.daizhongdai.xyz:3007/classify?zid=下饭菜',
      success:res=>{
        console.log(res.data.data.data);
        this.setData({
          caidan:res.data.data.data,
        })
      }
    })
  }else if(index==2){
    wx.request({
      url: 'https://www.daizhongdai.xyz:3007/classify?zid=朋友聚餐',
      success:res=>{
        console.log(res.data.data.data);
        this.setData({
          caidan:res.data.data.data,
        })
      }
    })
  }else if(index==3){
    wx.request({
      url: 'https://www.daizhongdai.xyz:3007/classify?zid=煮',
      success:res=>{
        console.log(res.data.data.data);
        this.setData({
          caidan:res.data.data.data,
        })
      }
    })
  }else if(index==4){
    wx.request({
      url: 'https://www.daizhongdai.xyz:3007/classify?zid=煲汤',
      success:res=>{
        console.log(res.data.data.data);
        this.setData({
          caidan:res.data.data.data,
        })
      }
    })
  }else if(index==5){
    wx.request({
      url: 'https://www.daizhongdai.xyz:3007/classify?zid=西餐',
      success:res=>{
        console.log(res.data.data.data);
        this.setData({
          caidan:res.data.data.data,
        })
      }
    })
  }
},
//点击右侧
 jumpCaiPu:function(e){
  //e.currentTarget.dataset.text获取点击的模块的值
    console.log(e);
    wx.navigateTo({
      url: '../dishDetails/dishDetails?info='+ encodeURIComponent(JSON.stringify(e.currentTarget.dataset.index)),
    })
    console.log(JSON.stringify(e.currentTarget.dataset.index));
    },
  /*
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  var that = this
      //获取tab的距离顶部高度
      const query = wx.createSelectorQuery();
      query.select('#tab').boundingClientRect(function (res) {
        // console.log(res.top)
        that.data.tabTop = res.top
      }).exec();
    console.log(this.data);
    wx.request({
      url: 'https://www.daizhongdai.xyz:3007/classify?zid=家常菜',
      success:res=>{
        console.log(res);
        this.data.caidaninfo=[];
        this.data.caidanxx.pic='';
        this.data.caidanxx.arrinfo={}
        for (const key in res.data.data.data) {
          this.data.caidanxx.pic=res.data.data.data[key].thumb.replace('http://','')
          this.data.caidanxx.arrinfo=res.data.data.data[key]
         this.data.caidaninfo.push(this.data.caidanxx)
         
        }
        console.log(this.data.caidaninfo);
        console.log(res.data.data.data[0].thumb);
        this.setData({
          caidan:res.data.data.data,
        })
      }
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})
